//
//  Status.swift
//  weibo
//
//  Created by 张宏芝 on 15/9/5.
//  Copyright © 2015年 kama. All rights reserved.
//

import UIKit

class Status: NSObject {
    
    /// 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?{
        didSet{
//            一旦给source设置数值之后,立即提取文本连接并且保存
//            在didSet中,给本属性设置数值,不会再次调用didSet
            source = source?.href()?.text
        }
    }
    /// 配图数组
    var pic_urls:[[String:String]]?
    /// 用户模型 － 如果直接使用 KVC，会变成字典
    var user: User?
    /// 被转发的原创微博对象
    var retweeted_status:Status?
    
//    MARK:构造函数
    init(dict:[String:AnyObject]){
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            user = User(dict: value as! [String:AnyObject])
            return
    }
    if key == "retweeted_status"{
        retweeted_status = Status(dict: value as! [String:AnyObject])
        return
        }
        
        super.setValue(value, forKey: key)
}
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
    
    override var description:String{
        let keys = ["created_at", "id", "text", "source", "pic_urls","user","retweeted_status"]
        return dictionaryWithValuesForKeys(keys).description
    }
}






























